package com.itrencai.d15_inetaddress;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class InetAddressDemo1 {
    public static void main(String[] args) throws Exception {
        //1.获取本机地址对象
        InetAddress ip1=InetAddress.getLocalHost();
        System.out.println(ip1);
        System.out.println(ip1.getHostName());
        System.out.println(ip1.getHostAddress());
        //2.获取域名ip对象
        InetAddress ip2=InetAddress.getByName("www.baidu.com");
        System.out.println(ip2.getHostAddress());
        System.out.println(ip2.getHostName());
        //3.获取公网的ip地址
        InetAddress ip3=InetAddress.getByName("36.152.44.96");
        System.out.println(ip3.getHostAddress());
        System.out.println(ip3.getHostName());
        //4.判断是否能通，ping 5s之前测试是否可
        System.out.println(ip3.isReachable(5000));
    }
}
